<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true" style="padding: 15px;margin-top: -20px;">
      <el-form-item :label="$t('估值方法')" prop="method">
        <el-input
          v-model="queryParams.method"
          :placeholder="$t('估值方法')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('状态')" prop="status">
        <el-select v-model="queryParams.status" :placeholder="$t('状态')" clearable>
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">-->
    <!--  <el-col :span="1.5">-->
    <!--    <el-button-->
    <!--      type="primary"-->
    <!--      icon="el-icon-plus"-->
    <!--      size="mini"-->
    <!--      @click="addHandle"-->
    <!--    >{{ $t('新增') }}</el-button>-->
    <!--  </el-col>-->
    <!--</el-row>-->

    <el-table v-loading="loading" :data="dealValuationSettingList" border tooltip-effect="darkTable" style="margin-top: 30px;">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('估值方法')" align="center" prop="method" />
      <el-table-column :label="$t('状态')" align="center" prop="status">
        <template slot-scope="scope">
          <span :style="{ color: (scope.row.status === 'enable' || scope.row.status === 'default') ? 'green' : 'red' }">{{ statusFormat(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" align="center" prop="remark" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改估值方法配置对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealValuationSettingForm ref="dealValuationSettingForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealValuationSetting } from '@/api/deal/analysisValuation/dealValuationSetting'
import dealValuationSettingForm from './dealValuationSettingForm.vue'
export default {
  components: {
    dealValuationSettingForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 估值方法配置表格数据
      dealValuationSettingList: [],
      // 弹出层标题
      title: '估值方法配置',
      // 是否显示弹出层
      formOpen: false,
      // 状态字典
      statusOptions: [],

      // 查询参数
      queryParams: {
        method: undefined,
        status: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('deal_valuation_setting_status').then(response => {
      this.statusOptions = response.data
    })
  },
  methods: {
    /** 查询估值方法配置列表 */
    getList() {
      this.loading = true
      listDealValuationSetting(this.queryParams).then(response => {
        this.dealValuationSettingList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        method: undefined,
        status: '0',
        formula: undefined,
        formulaFormat: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.dealValuationSettingForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.dealValuationSettingForm.init(row)
      })
    // },
    // /** 删除按钮操作 */
    // deleteHandle(row) {
    //   this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
    //     confirmButtonText: this.$t('确定'),
    //     cancelButtonText: this.$t('取消'),
    //     type: 'warning'
    //   }).then(() => {
    //     return delDealValuationSetting(row.id)
    //   }).then(() => {
    //     this.getList()
    //     this.msgSuccess(this.$t('删除成功'))
    //   }).catch(() => {
    //     this.loading = false
    //   })
    }
  }
}
</script>
